<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const str = '85872637471533203552943982'
        const arr = str.split('')
        // 需求1
        function dispose(arr) {
            // 声明空对象,用于接收创建都对象
            let x = {}
            // 判断出现次数
            arr.forEach(item => {
                if (x[item]) {
                    x[item]++
                } else {
                    x[item] = 1
                }
            })
            let max = 0   // 设定出现最多数次数初始值
            let key = 0   // 设定出现最多数初始值 
            for (let k in x) {
                if (max < x[k]) {
                    key = k
                    max = x[k]
                }
            }
            console.log(`出现次数最多的数为${key},出现次数为${max}次`)
        }
        dispose(arr)

        // 需求2
        // 去重
        function remova(arr) {
            const newArr = []
            arr.forEach(item => {
                !newArr.includes(item) ? newArr.push(item) : ''
            })
            return newArr
        }
        const res = remova(arr)
        console.log(`去重${res}`)

        //需求3 排序
        function sort(arr) {
            return arr.sort((a, b) => a - b)
        }
        const reslut = sort(res).join('')
        console.log(reslut)
    </script>
</body>

</html>